package com.huarui.company.action;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.ewaf.framework.action.BaseAction;

import com.huarui.company.model.Company;
import com.huarui.company.service.CompanyService;
import com.huarui.user.model.SessionMessage;
import com.huarui.user.security.UserHolder;

public class CheckCompanyAction extends BaseAction{
	
	public static String MESS = "mess";

	private static final long serialVersionUID = -626956616450844205L;
	
//	private String companyId;
	
	private Map<String, Object> mesMap;
	
	private CompanyService companyService;
	
//	public String getCompanyId() {
//		return companyId;
//	}
//
//	public void setCompanyId(String companyId) {
//		this.companyId = companyId;
//	}

	public Map<String, Object> getMesMap() {
		return mesMap;
	}

	public void setMesMap(Map<String, Object> mesMap) {
		this.mesMap = mesMap;
	}

	public void setCompanyService(CompanyService companyService) {
		this.companyService = companyService;
	}

	public String checkRealTypeAndPaid() {
		mesMap = new HashMap<String, Object>();
		
		SessionMessage se = UserHolder.getCurrentSessionMessage();
		Integer companyId = se.getCompanyId();
		
		if(null == companyId) {
			return MESS;
		}
		
		Company c = (Company) companyService.getById(companyId);
		if(c == null || c.getRealType() == null || c.getPaid() == null) return MESS;
		
		if(Company.PAID_YES == c.getPaid()) {
			mesMap.put("companyPaid", "1");
		} else {
			mesMap.put("companyPaid", "0");
		}
		
		if(Company.AUTHENTICATION_TYPE_NONE != c.getRealType()) {
			mesMap.put("realType", "1");
		} else {
			mesMap.put("realType", "0");
		}
		
		return MESS;
	}

}
